<?php
class Wmp_Form extends Zend_Form
{
    protected $_customDecorator;
	public function init()
    {
        $this->_customDecorator = zend_registry::get('config')->form->decorator;
    	
        if( $this->_customDecorator=="dojo" ) {// Dojo-enable the form: 
        	Zend_Dojo::enableForm($this); //INFO : j'ai prévu ici la possibilité d'utiliser jQuery etc
        	
	        // Dojo-enable all sub forms:
	        foreach ($this->getSubForms() as $subForm) {
	            Zend_Dojo::enableForm($subForm);
	        }
        }
        
        $this->addElementPrefixPath('Wmp_Decorator', 'Wmp/Decorator/', 'decorator');
		$this->addElementPrefixPath('Wmp_Filter', 'Wmp/Filter/', 'filter');
		$this->addElementPrefixPath('Wmp_Validate', 'Wmp/Validate/', 'validate');

    }
    
    public function setWmpDecorators()
    {
    	if( $this->_customDecorator=="dojo" ) {						
	        $this->setDecorators(array(
				    'FormElements',
				    array('TabContainer', array(
				        'id'          => 'tabContainer',
				        'style'       => 'width: 600px; height: 200px;',
				        'dijitParams' => array(
				            'tabPosition' => 'top'
				        ),
				    )),
				    'DijitForm',
			));			
						
			/*$formElements = $this->getElements();
			foreach($formElements as $currentElement)
				$currentElement->setDecorators(array(
			    'DijitElement',
			    'Errors',
			    'Label',
			    'ContentPane',			    
			));*/
		}
		else if( $this->_customDecorator=="zend" ) { //zend decorator
			$this->setDecorators(array(
	            'FormElements',
	            array('HtmlTag', array('tag' => 'dl', 'class' => 'wmp_form')),
	            array('Description', array('placement' => 'prepend')),
	            'Form'
        	));
			
			$commonElementdecorators = array(
	            array('ViewHelper'), 
	            array('Description'),
	            array('Errors'),
	            array('Label', array('separator'=>' ', 'requiredSuffix' => ' *', 'class' => 'lefty')),
	            array('HtmlTag', array('tag' => 'li')),
        	);			
			
        	$formElements = $this->getElements();
			foreach($formElements as $currentElement)
				$currentElement->setDecorators($commonElementdecorators);			
		}
    	else if( $this->_customDecorator=="jquery" ) {
			//just in case	
		}		
    }
}